home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / tsfaqp34.zip / FAQPAS2.TXT < prev    next >
Internet Message Format  |  1996-09-07  |  46KB

  1. From ts@uwasa.fi Sat Sep 7 00:00:00 1996
  2. Subject: FAQPAS2.TXT contents
  3.  
  4.                              Copyright (c) 1993-1996 by Timo Salmi
  5.                                                All rights reserved
  6.  
  7. FAQPAS2.TXT More frequently (and not so frequently) asked Turbo
  8. Pascal questions with Timo's answers. The items are in no particular
  9. order.
  10.  
  11. You are free to quote brief passages from this file provided you
  12. clearly indicate the source with a proper acknowledgment.
  13.  
  14. Comments and corrections are solicited. But if you wish to have
  15. individual Turbo Pascal consultation, please post your questions to
  16. a suitable Usenet newsgroup like news:comp.lang.pascal.borland. It
  17. is much more efficient than asking me by email. I'd like to help,
  18. but I am very pressed for time. I prefer to pick the questions I
  19. answer from the Usenet news. Thus I can answer publicly at one go if
  20. I happen to have an answer. Besides, newsgroups have a number of
  21. readers who might know a better or an alternative answer. Don't be
  22. discouraged, though, if you get a reply like this from me. I am
  23. always glad to hear from fellow Turbo Pascal users.
  24.  
  25. ....................................................................
  26. Prof. Timo Salmi   Co-moderator of news:comp.archives.msdos.announce
  27. Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
  28. Department of Accounting and Business Finance  ; University of Vaasa
  29. ts@uwasa.fi http://uwasa.fi/~ts BBS 961-3170972; FIN-65101,  Finland
  30.  
  31. --------------------------------------------------------------------
  32. 26) How to get ansi control codes working in Turbo Pascal writes?
  33. 27) How to evaluate a function given as a string to the program?
  34. 28) How does one detect whether input (or output) is redirected?
  35. 29) How does one set the 43/50 line text mode?
  36. 30) How can I assign a value to an environment variable in TP?
  37. 31) How does one store, and then restore the original screen?
  38. 32) How can I convert a TPU unit of one TP version to another?
  39. 33) Which error is e.g. Runtime error 205, etc
  40. 34) Why can't I open read-only files? I get "File access denied".
  41. 35) How do I obtain high and low parts of a byte variable?
  42. 36) How can I set a hi-intensity color background in the text mode?
  43. 37) Where can I find a program to convert (Turbo) Pascal to C?
  44. 38) How can I read input without echoing to the screen?
  45. 39) How can I edit the readln input stream?
  46. 40) How can I write (brand) something into my executables?
  47. 41) What is wrong with my program? It hangs without a clear pattern?
  48. 42) How do I convert a decimal word into a hexadecimal string, etc?
  49. 43) How to determine the last drive?
  50. 44) How can I put a running clock into my Turbo Pascal program?
  51. 45) How to establish if a name refers to a directory or not?
  52. 46) How does one disable alt-ctrl-del?
  53. 47) How can I test whether a file exists?
  54. 48) What is the name of the current Turbo Pascal program?
  55. 49) How is the code for rebooting the PC written in Turbo Pascal?
  56. 50) How can I write inline code?
  57. --------------------------------------------------------------------
  58.  
  59. From ts@uwasa.fi Sat Sep 7 00:00:26 1996
  60. Subject: Using ansi codes in a TP program
  61.  
  62. 26. *****
  63.  Q: How to get ansi control codes working in Turbo Pascal writes?
  64.  
  65.  A: It is very simple, but one has to be aware of the pitfalls.
  66. Let's start from the assumption that ansi.sys or a corresponding
  67. driver has been loaded, and that you know ansi codes. If you don't,
  68. you'll find that information in the standard MS-DOS manual. To apply
  69. ansi codes you just include the ansi codes in your write statements.
  70. For example the following first clears the screen and then puts the
  71. text at location 10,10:
  72.    write (#27, '[2J');         (* the ascii code for ESC is 27 *)
  73.    write (#27, '[10;10HUsing ansi codes can be fun');
  74. If you want to test (as you should) whether ansi.sys or some some
  75. replacement driver has been loaded, you can use the ISANSIFN
  76. function from my ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip.
  77. Now the catches. If you have a
  78.    uses Crt;
  79. statement in your program, direct screen writes will be used, and
  80. the ansi codes won't work. You have either to leave out the Crt
  81. unit, or include
  82.    assign (output, '');
  83.    rewrite (output);
  84.    :
  85.    close (output);
  86. Occasionally I have seen it suggested that one should just set
  87.    DirectVideo := false;
  88. This is a popular misconception. It won't produce the desired
  89. result. I'm not claiming to know the reason for this quirk of Turbo
  90. Pascal. Rather it is an observation I've made.
  91.  
  92. -From: Bengt Oehman d92bo@efd.lth.se with a later dicussion with Bob
  93. Peck bpeck@prairienet.org and help from Duncan Murdoch
  94. dmurdoch@mast.queensu.ca. The `DirectVideo:=False' statement only
  95. tells the Crt unit to use BIOS calls instead of using direct
  96. video-memory writes. A demo program to illustrate the screen writing
  97. modes follows:
  98.  
  99. Program ScreenWriteDemo;
  100. USES Crt;
  101. BEGIN
  102.   Writeln('This is written directly to the video memory');
  103.   DirectVideo:=False;
  104.   Writeln('This is written via BIOS interrupt calls (int 10h)');
  105.   Assign(Output,'');
  106.   Append(Output);
  107.   Writeln('This is written via DOS calls (int 21h)');
  108. END.
  109.  
  110. A note: The latter could be also written as
  111.   Writeln(Output, 'This is written via DOS calls (int 21h)');
  112. since the writeln default is the standard output.
  113. --------------------------------------------------------------------
  114.  
  115. From ts@uwasa.fi Sat Sep 7 00:00:27 1996
  116. Subject: Writing an expression parser
  117.  
  118. 27. *****
  119.  Q: How to evaluate a function given as a string to the program?
  120.  
  121.  A: To do this you have to have a routine for parsing and evaluating
  122. your expression. This is a complicated task requiring a clever use
  123. of recursion. You can find such code in Stephen O'Brien (1988),
  124. Turbo Pascal, The Complete Reference. Borland-Osborne/McGraw-Hill,
  125. Chapter 10. Another, simpler piece of code can be found in Michael
  126. Yester (1989), Using Turbo Pascal, Que, Chapter 5.
  127.    I've also written such a function evaluation program myself, and
  128. much of it is based on the ideas in O'Brien with my own corrections
  129. and enhancements. The resulting program is available as fn.exe
  130. function evaluator in the ftp://garbo.uwasa.fi/pc/ts/tsfunc13.zip
  131. package (or whatever version number is the latest). Note however,
  132. that the source code is not included, nor available.
  133.    Tips from Justin Lee (ossm1jl@rex.uokhsc.edu):
  134.  67666 Sep 22 1994 ftp://garbo.uwasa.fi/pc/turboobj/parstp30.zip
  135.  parstp30.zip Recursive expression TP7.0/BP/VB/C++ parser, R.Loewy
  136. An excellent parser is included with all the Turbo Pascal versions
  137. since TP4.0 as part of the MCALC or TCALC spreadsheet example
  138. program. See mcparse.pas or tcparse.pas.
  139. --------------------------------------------------------------------
  140.  
  141. From ts@uwasa.fi Sat Sep 7 00:00:28 1996
  142. Subject: Detecting redirection
  143.  
  144. 28. *****
  145.  Q: How does one detect whether input (or output) is redirected?
  146.  
  147.  A: As we know input to a program can come from a file, from the
  148. console, or from a pipe or redirection. Examples of the latter are
  149.      type text.dat | program
  150.      program < text.dat
  151. A Turbo Pascal program can be made to detect the redirections using
  152. Interrupt 21Hex, function 44Hex, subfunction 00Hex. See PC Magazine
  153. April 16, 1991, p. 374 for the code, and Duncan (1988), Advanced
  154. MS-DOS Programming, pp. 412-413 for more information. Alternatively,
  155. you can utilize the preprogrammed routines
  156.   PIPEDIFN Is the standard input from redirection
  157.   PIPEDNFN Is the standard output redirected to nul
  158.   PIPEDOFN Is the standard output redirected
  159. from my ftp://garbo.uwasa.fi/pc/ts/tspa3570.zip units.
  160. --------------------------------------------------------------------
  161.  
  162. From ts@uwasa.fi Sat Sep 7 00:00:29 1996
  163. Subject: Setting the 43/50 line text mode
  164.  
  165. 29. *****
  166.  Q: How does one set the 43/50 line text mode?
  167.  
  168.  A: Quite simple. Just apply TextMode (C80 + font8x8).  Requires a
  169. "uses Crt;". First, however, you should test that you have a at
  170. least an EGA video adapter. (See DetectGraph in your TP manual).
  171. Also see TSUTLE.NWS in ftp://garbo.uwasa.fi/pc/ts/tsutle22.zip (or
  172. whichever version number is the current) for the